<?php

class UserController extends Zend_Controller_Action 
{
    protected $_model;

    public function indexAction()
    {
        $model = $this->_getModel();
        $this->view->entries = $model->fetchEntries();
    }

    public function passwordAction()
    {
        $request = $this->getRequest();
        if($request->isPost()){
            $user = $this->_getModel();
            $prev_pass = $request->getParam('prev_pass');            
            $pass = $request->getParam('pass');            
            $u = $user->getUser($email);
            if(isset($u)){
                $u->password = $pass;
                $u->save();                                
            }else{
                $json = array();
                $json['success'] = false;
                $errors['prev_pass'] = 'Incorect password!';
                $json['errors'] = $errors;
                echo Zend_Json::encode($json);
            }            
            die();
        }                
    }

    protected function _getModel()
    {
        if (null === $this->_model) {
            require_once APPLICATION_PATH . '/models/User.php';
            $this->_model = new Model_User();
        }
        return $this->_model;
    }
}
